package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.good.Goods;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin")
public class GoodsController {
    @Autowired
    GoodsService goodsService;
    @RequestMapping("goods/list")
    /**
     * 首页，显示所有商品
     */
    public BaseRespVo goodsList(Integer page,Integer limit,String sort,String order,Integer goodsSn,String name){
        GoodsVo<Goods> goodsvo=goodsService.queryGoodsList(page, limit, sort, order, goodsSn, name);
        return BaseRespVo.ok(goodsvo);
    }

    /**
     * 显示商品详情
     * @param id
     * @return
     */
    @RequestMapping("goods/detail")
    public BaseRespVo goodsdetail(Integer id){
          GoodsListVO goodsGoodsListVO=goodsService.queryGoodsDetail(id);
          return BaseRespVo.ok(goodsGoodsListVO);
    }

    /**
     * 显示品牌信息
     * @return
     */
    @RequestMapping("goods/catAndBrand")
    public  BaseRespVo querygoodscatAndBrand(){

        CatAndBrandVO data = goodsService.goodsCatAndBrand();
        return BaseRespVo.ok(data);
    }

    /**
     * 新增商品
     * @param goods
     * @return
     */
    @RequestMapping("goods/create")
    public BaseRespVo createGoods(@RequestBody GoodsBO goods){
        goodsService.createGoods(goods);
        return BaseRespVo.ok();
    }

    /**
     * 更新商品
     * @param
     * @return
     */
    @RequestMapping("goods/update")
    public BaseRespVo updateGoods(@RequestBody GoodsBO goodsBO) {
       goodsService.updateGoods(goodsBO);
        return BaseRespVo.ok();
    }

    /**
     * 删除商品
     * @param goods
     * @return
     */
    @RequestMapping("goods/delete")
    public BaseRespVo deleteGoods(@RequestBody Goods goods){
        goodsService.deleteGoods(goods);
            return BaseRespVo.ok();
    }
}
